//src/utils/map.ts

import "leaflet/dist/leaflet.css";
import L from "leaflet";

//卫星地图
// const osmUrl ="https://wprd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scl=1&style=7&x={x}&y={y}&z={z}";
const osmUrl = "http://search.jms.gd/tile/shiliang/{z}/{x}/{y}.png";

export function createMap(divId: string, options: any): any {
  //卫星地图

  const tiandituMap = L.tileLayer(osmUrl);

  options.maxZoom = 19;

  const layers = L.layerGroup([tiandituMap]);
  const map = L.map(divId, {
    //需绑定地图容器div的id
    center: [39.56, 116.2], //初始地图中心
    zoom: 10, //初始缩放等级
    maxZoom: 19, //最大缩放等级
    minZoom: 0, //最小缩放等级
    doubleClicjZoom: false,
    zoomControl: false, //不显示缩放小控件
    layers: [layers]
  });

  return map;
}

export function addMapMarker(mapInstance, location: [number, number]): void {
  L.marker(location).addTo(mapInstance);
}

export function setMapView(mapInstance, location: [number, number]): void {
  const center = L.latLng(location[0], location[1]);

  mapInstance.setView(center, 14);
}
